<template>
  <div class="process-inspection-todo-page">
    <div class="page-header"></div>
    <div class="page-container">
      <div class="table-header" header="待办事项"></div>
      <div class="table-list" v-loading="loading">
        <vxe-table
          height="99%"
          class="scrollbarStyle"
          align="center"
          :data="tableData"
          :column-config="{ resizable: true }"
          show-overflow
          show-header-overflow
        >
          <vxe-column type="seq" width="80" title="序号"></vxe-column>
          <vxe-column field="trialDate" title="试验时间"> </vxe-column>
          <vxe-column field="parentName" title="试验类型"> </vxe-column>
          <vxe-column field="trialName" title="试验项目"> </vxe-column>
          <vxe-column field="standardValue" title="技术指标"> </vxe-column>
          <vxe-column field="testValue" title="实测结果"> </vxe-column>
          <vxe-column field="testValue" title="结果判定">
            <template #default="{ row }">
              <div :class="['status-text', checkStatusClass(row)]">
                {{
                  row.result == 0 ? "合格" : row.result == 1 ? "不合格" : "-"
                }}
              </div>
            </template>
          </vxe-column>
          <vxe-column field="operate" width="160" title="操作" fixed="right">
            <template #default="{ row }">
              <div class="text-button-group">
                <a-button
                  type="link"
                  v-if="row.dealStatus == 0"
                  @click="goDetail(row, '2')"
                >
                  处理
                </a-button>
                <a-button
                  type="link"
                  v-if="row.dealStatus == 1"
                  @click="goDetail(row, '3')"
                >
                  闭合
                </a-button>
              </div>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div>
        <vxe-pager
          background
          :current-page.sync="pager.page"
          :page-size.sync="pager.pageSize"
          :total="pager.total"
          :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'Sizes', 'FullJump']"
          @page-change="paginationChange"
        >
          <template #left>
            <div class="vxe-pager-left-tip-container">
              第<span>1</span>到<span
                >{{ Math.ceil(pager.total / pager.pageSize) || 1 }}页 </span
              >共<span>{{ pager.total }}</span
              >条记录
            </div>
          </template>
        </vxe-pager>
      </div>
    </div>

    <!-- 操作页面 -->
    <viewPage
      :visible.sync="pageVisible"
      :title="parameter.title"
      :pId="parameter.id"
      :reId="parameter.reportId"
      :parentNum="parameter.parentNum"
      :trialNum="parameter.trialNum"
    ></viewPage>
  </div>
</template>

<script>
import viewPage from "./components/view.vue";
import { getSYGLXTList } from "@/api/todo";
export default {
  components: {
    viewPage,
  },
  props: ["isMenuCode"],
  inject: ["upLeave"],
  watch: {
    isMenuCode: {
      handler(val) {
        if (val == "SYGLXT") {
          this.getData();
        }
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      loading: false,
      tableData: [],
      pager: {
        page: 1,
        pageSize: 10,
        total: 0,
      },
      //查看
      pageVisible: false,
      parameter: {
        title: "",
        id: "",
        reportId: "",
        trialNum: "",
        parentNum: "",
      },
    };
  },
  methods: {
    //处理
    goDetail(record, type) {
      let title = "";
      switch (type) {
        case "2":
          title = "处理";
          break;
        case "3":
          title = "闭合";
          break;

        default:
          break;
      }
      this.parameter = {
        title,
        id: record.id,
        reportId: record.trialReportId,
        parentNum: record.parentNum,
      };
      this.pageVisible = true;
    },

    getData() {
      this.upLeave.getTodoData();
      this.pager.page = 1;
      this.getTableData();
    },

    //查询列表
    getTableData() {
      this.loading = true;
      let { page, pageSize } = this.pager;
      return new Promise((resolve, reject) => {
        getSYGLXTList({
          page,
          pageSize,
        })
          .then((res) => {
            let { data } = res;
            this.tableData = data.result?.records || [];
            this.pager.total = data?.result?.total || 0;
            resolve();
          })
          .catch((_) => {
            this.tableData = [];
            this.pager.total = 0;
            reject();
          })
          .finally((_) => {
            this.loading = false;
          });
      });
    },

    //监听分页切换
    paginationChange({ currentPage, pageSize }) {
      this.pager.page = currentPage;
      this.pager.pageSize = pageSize;
      this.getTableData();
    },

    //校验状态className
    checkStatusClass(row) {
      let { result } = row;
      switch (result) {
        case 0:
          return "normal";

        case 1:
          return "error";

        default:
          return "cancel";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.process-inspection-todo-page {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  .page-header {
    .conditions-screening-container {
      box-shadow: none;
    }
    margin-bottom: 10px;
  }
  .page-container {
    flex: 1;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    .table-header {
      padding: 20px 20px;
      box-sizing: border-box;
      .flex();
      justify-content: space-between;
      align-items: center;
      &::before {
        content: attr(header);
        height: 18px;
        border-left: 3px solid var(--primary-color);
        padding-left: 10px;
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #525a5d;
        line-height: 18px;
      }
    }
    .table-list {
      flex: 1;
      height: 100%;
      .status-text {
        border-radius: 4px;
        color: #fff;
        .flex();
        align-items: center;
        justify-content: center;
        margin: 0 auto;
        font-size: 12px;
        width: 80px;
        &.lock {
          background: #0098ff;
        }
        &.warn {
          background: #ff993f;
        }
        &.approv {
          background: #ff7113;
        }
        &.normal {
          background: #4bc964;
        }
        &.error {
          background: #ff3f4a;
        }
        &.cancel {
          background: #f1f2f7;
          color: #aab0bc;
        }
      }
    }
  }
}
</style>
